Option Strict Off
Option Explicit On
Namespace BMLERP
	Friend Class frmReview
		Inherits System.Windows.Forms.Form
		Dim frmreviewTag As String
		Sub MoFile(ByRef Loai As Object)
			'27/04/2004 Bo sung ord540 thay ehstt=b
			Dim dem As Byte
			dem = 1
			On Error GoTo ktra
			Adodc1.ConnectionString = ConnectString
			Adodc1.ConnectionTimeout = 40
			Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText
			Dim mloai As TextBox = Loai
			Select Case mloai.Text
				Case "INV500"
					Adodc1.RecordSource = "SELECT GroupITHDoc.*" & " From GroupITHDoc" & " WHERE (Month(THDTE)=" & Val(txtMonth.Text) & ") And (Year(THDTE)= " & Val(txtYear.Text) & ")" & " ORDER BY THDTE DESC, THDOC DESC"
				Case "INV540"
					Adodc1.RecordSource = "SELECT TCTNO,TCDTE from ICT " & " where (month(TCDTE)=" & Val(txtMonth.Text) & ") And (Year(TCDTE)= " & Val(txtYear.Text) & ")" & " group by TCTNO,TCDTE"
				Case "BBL500"
					Adodc1.RecordSource = "Select * from BBH where (month(BHDTE)=" & Val(txtMonth.Text) & ") And (Year(BHDTE)= " & Val(txtYear.Text) & ")" & " AND ((BBH.BHFOD IS NULL) OR (BBH.BHFOD <> 'Y')) " & " ORDER BY BHDTE DESC,BHIVN DESC"
				Case "BBL400"
					Adodc1.RecordSource = "Select * from BBH where  BBH.BHSTT='1'  ORDER BY BHDTE DESC,BHIVN DESC"
				Case "BBL410"
					Adodc1.RecordSource = "Select * from BBH where  BBH.BHSTT='2'  ORDER BY BHDTE DESC,BHIVN DESC"
				Case "ORD500"
					Adodc1.RecordSource = "Select * from ECH where (month(EHDTE)=" & Val(txtMonth.Text) & ") And (Year(EHDTE)= " & Val(txtYear.Text) & ")" & " ORDER BY EHDTE DESC,EHODN DESC"
				Case "ORD540"
					' Adodc1.RecordSource = "Select * from ECH where (month(EHDTE)=" & Val(txtMonth) & ") And (Year(EHDTE)= " & Val(txtYear) & ")" & _
					'" AND (EHSTT='1' OR EHSTT='2' OR EHSTT='3' OR EHSTT='4') ORDER BY EHODN DESC"
					Adodc1.RecordSource = "Select ech.ehodn from ECH where (month(EHDTE)=" & Val(txtMonth.Text) & ") And (Year(EHDTE)= " & Val(txtYear.Text) & ")" & " AND ((EHSTT='B')OR (EHSTT='2'))  ORDER BY EHDTE DESC,EHODN DESC"
				Case "ORD560"

					Adodc1.RecordSource = "Select * from ECH where (month(EHDTE)=" & Val(txtMonth.Text) & ") And (Year(EHDTE)= " & Val(txtYear.Text) & ")" & " AND (EHSTT='2') ORDER BY EHDTE DESC,EHODN DESC"
				Case "PUR500"
					Adodc1.RecordSource = "Select * from POH where (month(OHPOD)=" & Val(txtMonth.Text) & ") And (Year(OHPOD)= " & Val(txtYear.Text) & ")" & " ORDER BY OHPOD DESC,OHPON DESC"
					'MsgBox "Select * from POH where (month(OHPOD)=" & Val(txtMonth) & ") And (Year(OHPOD)= " & Val(txtYear) & ")" & _
					'" ORDER BY OHPON DESC"
				Case "ACR500"
					Adodc1.RecordSource = "Select * from ACR where (month(ARDTE)=" & Val(txtMonth.Text) & ") And (Year(ARDTE)= " & Val(txtYear.Text) & ")" & " ORDER BY ARDOC DESC"
				Case "RAR500"
					Adodc1.RecordSource = "Select ARDOC, CMCNO from RAR where (month(ARDTE)=" & Val(txtMonth.Text) & ") And (Year(ARDTE)= " & Val(txtYear.Text) & "AND ARTYP='P' " & ")" & " GROUP BY ARDOC, CMCNO ORDER BY ARDOC DESC"
			End Select

			Adodc1.Refresh()
			' MsgBox Adodc1.Recordset.RecordCount
			'GridList.CtlRefresh()
			GridList.Refresh()
			Exit Sub
Reconnect:
			Adodc1.ConnectionString = ConnectString
			Adodc1.ConnectionTimeout = 40
			Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText

ktra:
			If Err.Description = "[Microsoft][ODBC SQL Server Driver]Timeout expired" Then
				dem = dem + 1
				GoTo Reconnect
				If dem > 3 Then
					MsgBox("Dang nghe~n duong mang vao lai chuong trinh sau.")
					End
				End If
			End If
		End Sub




		Private Sub frmReview_Activated(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Activated
			txtLoai.Text = Me.Tag
			MoFile(txtLoai)
			VB6_AddADODataBinding()
			ManHinh(txtLoai)


		End Sub

		Private Sub frmReview_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
			Me.Tag = Nothing
		End Sub
		Private Sub FrmMainMenu_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
			Me.Tag = Nothing
		End Sub

		Private Sub frmReview_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load



			txtMonth.Text = CStr(Month(WorkingDate))
			txtYear.Text = CStr(Year(WorkingDate))
			Dim myDataCaptions As String() = {"Doc No", "Trans Code", "Trans Desc"}
			Dim myDataFields As String() = {"THDOC", "THTTC", "TCDSC"}
			setDataGridView(myDataCaptions, myDataFields, Me.GridList)

		End Sub

		Private Sub gridlist_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles GridList.DblClick

			If Adodc1.Recordset.RecordCount > 0 Then
				Me.Tag = GridList.Columns(1).Value
			Else
				Me.Tag = ""
			End If
			Me.Hide()
		End Sub



		Private Sub txtyear_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtYear.TextChanged
			If txtLoai.Text <> "" Then
				MoFile(txtLoai)
			End If

		End Sub

		Private Sub txtmonth_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMonth.TextChanged
			If txtLoai.Text <> "" Then
				MoFile(txtLoai)
			End If
		End Sub
		Sub ManHinh(ByRef Loai As Object)
			Dim mloai As TextBox = Loai
			Select Case mloai.Text
				Case "INV500"

					Dim myDataFields As String() = {"THDOC", "THDTE", "THTTC"}
					Dim myDataCaptions As String() = {"Doc No", "Item", "Trans Desc"}
					setDataGridView(myDataCaptions, myDataFields, GridList)
				Case "INV540"

					Dim myDataFields As String() = {"TCTNO", "TCDTE"}
					Dim myDataCaptions As String() = {"Tag No", "Tag Date"}
					setDataGridView(myDataCaptions, myDataFields, GridList)
				Case "BBL500"

					Dim myDataFields As String() = {"BHIVN", "BHDTE"}
					Dim myDataCaptions As String() = {"Invoice No", "Invoice Date"}
					setDataGridView(myDataCaptions, myDataFields, GridList)
				Case "BBL400"
					txtMonth.Visible = False
					txtYear.Visible = False

					Dim myDataFields As String() = {"BHIVN", "BHDTE"}
					Dim myDataCaptions As String() = {"Invoice No", "Invoice Date"}
					setDataGridView(myDataCaptions, myDataFields, GridList)
				Case "BBL410"
					txtMonth.Visible = False
					txtYear.Visible = False


					Dim myDataFields As String() = {"BHIVN", "BHDTE"}
					Dim myDataCaptions As String() = {"Invoice No", "Invoice Date"}
					setDataGridView(myDataCaptions, myDataFields, GridList)
				Case "ORD500"


					Dim myDataFields As String() = {"EHODN", "EHDTE"}
					Dim myDataCaptions As String() = {"Order No", "Order Date"}
					setDataGridView(myDataCaptions, myDataFields, GridList)
				Case "ORD540"

					Dim myDataFields As String() = {"EHODN", "EHDTE"}
					Dim myDataCaptions As String() = {"Order No", "Order Date"}
					setDataGridView(myDataCaptions, myDataFields, GridList)
				Case "ORD560"

					Dim myDataFields As String() = {"EHODN", "EHDTE"}
					Dim myDataCaptions As String() = {"Order No", "Order Date"}
					setDataGridView(myDataCaptions, myDataFields, GridList)
				Case "PUR500"


					Dim myDataFields As String() = {"OHPON", "OHPOD"}
					Dim myDataCaptions As String() = {"PO No", "PO Date"}
					setDataGridView(myDataCaptions, myDataFields, GridList)
				Case "ACR500"

					Dim myDataFields As String() = {"ARDOC", "ARRFD", "ARDTE"}
					Dim myDataCaptions As String() = {"DOC No", "Ref No", "Date"}
					setDataGridView(myDataCaptions, myDataFields, GridList)
				Case "RAR500"

					Dim myDataFields As String() = {"ARDOC", "ARDTE"}
					Dim myDataCaptions As String() = {"DOC No", "Date"}
					setDataGridView(myDataCaptions, myDataFields, GridList)
			End Select
		End Sub
	End Class
End Namespace